package app.menu;

import puri01.ValueList;
import puri01.game.GameControlGroup;
import puri01.game.GamePlatformInfo;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.Display;
import android.view.WindowManager;

public class Menu_Begin extends ProJect {

	public Menu_Begin(GameControlGroup gameControlGroup) {
		super(gameControlGroup);
		
		gameControlGroup.addControl(this);
	}

	private Canvas _Canvas = null;
	private Paint _Paint = null;
	private Bitmap _Bitmap = null;
	private long _DisplayTime = 0;

	@Override
	public void actionIn(ProJect oldScene, ValueList params) {
		_DisplayTime = 500;
	}

	@Override
	public void actionOut(ProJect oldScene) {
		_Bitmap = null;
	}

	@Override
	protected void onStart(GamePlatformInfo platformInfo) {
		_Canvas = platformInfo.getCanvas();
		_Paint = platformInfo.getPaint();
	}

	@Override
	protected void onDraw(GamePlatformInfo platformInfo) {
		Display display = ((WindowManager)platformInfo.getGamePlatform().getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
		int width = display.getWidth();
		int height = display.getHeight();
		_DisplayTime = _DisplayTime - platformInfo.getTick();
		if (_DisplayTime <= 0) {
			PJManager.getInstance().main(null);
			return;
		}
		
		if (_Bitmap == null) {
			_Bitmap = BitmapFactory.decodeResource(
					platformInfo.getGamePlatform().getContext().getResources(), 
					app.main.R.drawable.begin01);
			_Bitmap = Bitmap.createScaledBitmap(_Bitmap, width, height, true);
		}
		
		_Canvas.drawBitmap(_Bitmap, 0, 0, _Paint);
	}

}
